import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jinke/page/pro_list/subs/pro_open/subs/pro_open_step3/widgets/cell.dart';
import 'package:jinke/utils/date_format/date_util.dart';

import '../../../../../../utils/component/component.dart';
import '../../../../../../utils/component/selected_tag_view.dart';
import '../../../../../../utils/util.dart';
import '../../main/widgets/header.dart';
import '../../main/widgets/pro_brife.dart';
import 'index.dart';
import 'widgets/widgets.dart';

class ProOpenStep3Page extends StatelessWidget {
  ProOpenStep3Page({Key? key}) : super(key: key);
  final controller = Get.put(ProOpenStep3Controller());
  // 主视图
  Widget _buildView() {
    return ListView(
        padding: EdgeInsets.only(bottom: 80.r), children: _getCells()
        // children: [
        //   ProOpenStep3Header(),
        //   ProOpenStep3Cell(
        //     title: '线索阶段',
        //     content: controller.state.time1,
        //     isFirst: true,
        //     onChange: (p0) {
        //       controller.state.time1 = DateFormat.format(p0, DateFormatType.ymd);
        //       controller.update();
        //     },
        //   ),
        //   ProOpenStep3Cell(
        //     title: '签约阶段',
        //     content: controller.state.time2,
        //     onChange: (p0) {
        //       controller.state.time2 = DateFormat.format(p0, DateFormatType.ymd);
        //       controller.update();
        //     },
        //   ),
        //   ProOpenStep3Cell(
        //     title: '开工阶段',
        //     content: controller.state.time3,
        //     onChange: (p0) {
        //       controller.state.time3 = DateFormat.format(p0, DateFormatType.ymd);
        //       controller.update();
        //     },
        //   ),
        //   ProOpenStep3Cell(
        //     title: '投产阶段',
        //     isLast: true,
        //     content: controller.state.time4,
        //     onChange: (p0) {
        //       controller.state.time4 = DateFormat.format(p0, DateFormatType.ymd);
        //       controller.update();
        //     },
        //   ),
        // ],
        );
  }

  List<Widget> _getCells() {
    List<Widget> list = [ProOpenStep3Header()];
    list.addAll(controller.state.list
            ?.asMap()
            .map((key, e) => MapEntry(
                  key,
                  ProOpenStep3Cell(
                    isFirst: key == 0,
                    isLast: key + 1 == controller.state.list?.length,
                    title: e.name ?? '',
                    content: e.createTime,
                    onChange: (p0) {
                      e.createTime = DateFormat.format(p0, DateFormatType.ymd);
                      controller.update();
                    },
                  ),
                ))
            .values
            .toList() ??
        []);
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProOpenStep3Controller>(
      builder: (_) {
        return Scaffold(
          body: SafeArea(child: _buildView()),
        );
      },
    );
  }
}
